﻿#region  == Copyright == 
// =====================================================================
//  Microsoft Consulting Services France - Aymeric Mouillé - 2013
//  Projet     : TFS WorkItemTracker - TFS WorkItemTracker
//  Fichier    : MainForm.cs (01/05/2013 18:40)
//  
//  Copyright (C) Microsoft Corporation.  All rights reserved.
// =====================================================================
#endregion

namespace TFS.WorkItemTracker
{
    #region  == Using == 
    using System.Windows.Forms;

    using Microsoft.TeamFoundation.WorkItemTracking.Client;

    using TFS.WorkItemTracker.Properties;

    #endregion

    public partial class MainForm : Form
    {
        #region Selected Work Item Id
        /// <summary>
        /// Gets or sets the selected work item id.
        /// </summary>
        /// <value>
        /// The selected work item id.
        /// </value>
        public int SelectedWorkItemId { get; set; }
        #endregion

        #region = Constructor =
        /// <summary>
        /// Initializes a new instance of the <see cref="MainForm" /> class.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Main Form Load
        /// <summary>
        /// Handles the Load event of the MainForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">
        /// The <see cref="System.EventArgs" /> instance containing the event data.
        /// </param>
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(Settings.Default.TFSProjectCollectionUrl))
            {
                MessageBox.Show("You need to specified a TFS project collection url", "Missing parameter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                tabControl.SelectTab("tabSettings");

            }
            HideWorkItemDetail();
        }
        #endregion

        #region Hide Work Item Detail
        /// <summary>
        /// Hides the work item detail.
        /// </summary>
        public void HideWorkItemDetail()
        {
            tabControl.TabPages["tabWorkItemDetail"].Enabled = false;
            Application.DoEvents();
        }
        #endregion

        #region Set Status
        /// <summary>
        /// Sets the status.
        /// </summary>
        /// <param name="statusMessage">The status message.</param>
        public void SetStatus(string statusMessage)
        {
            lblStatus.Text = statusMessage;
        }
        #endregion

        #region Show Work Item Detail
        /// <summary>
        /// Shows the work item detail.
        /// </summary>
        public void ShowWorkItemDetail()
        {
            tabControl.TabPages["tabWorkItemDetail"].Enabled = true;
            Application.DoEvents();
        }
        #endregion

        #region Switch To Work Item Detail
        /// <summary>
        /// Switches to work item detail.
        /// </summary>
        public void SwitchToWorkItemDetail()
        {
            tabControl.TabPages["tabWorkItemDetail"].Enabled = true;
            tabControl.SelectTab("tabWorkItemDetail");
            Application.DoEvents();
        }
        #endregion

        #region Switch To Work Item List
        /// <summary>
        /// Switches to work item list.
        /// </summary>
        public void SwitchToWorkItemList()
        {
            tabControl.SelectTab("tabWorkItems");
            Application.DoEvents();
        }
        #endregion

        #region Open Change Set History
        /// <summary>
        /// Opens the change set history.
        /// </summary>
        public ChangeSetHistoryForm OpenChangeSetHistory(WorkItem workItem)
        {
            ChangeSetHistoryForm changeSetHistoryForm = new ChangeSetHistoryForm(workItem);
            changeSetHistoryForm.Show();
            return changeSetHistoryForm;
        }
        #endregion
    }
}
